package controllerTaf;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTable;

import domijn.Tafel;
import pnlRestaurant.PnlResMain;
import tblModelTafel.TMTafel;

public class TafBtnSave implements ActionListener {

	private PnlResMain pnlResMain;
	private JTable table;
	@SuppressWarnings("unused")
	private TMTafel tafelM;
	private Tafel tafel;

	public TafBtnSave(PnlResMain pnlResMain) {
	this.pnlResMain = pnlResMain;
	}

	@Override
	public void actionPerformed(ActionEvent i) {
		if (i.getActionCommand().equals("Save")){
			System.out.println("Save button is clicked");
			
		try{
			
		String nummer;
		nummer =  pnlResMain.getTxtTafelNummerR().getText();
		System.out.println(nummer);
		int n = Integer.valueOf(nummer);
	    tafel = new Tafel(n);
		tafel.save();
			    	
					 pnlResMain.getLblSaveMelding().setVisible(true);
					 pnlResMain.getLblDeleteMelding().setVisible(false);
					 pnlResMain.getTxtTafelNummerR().setText("");
					 table = pnlResMain.getTblTafel();
					 table.setModel(tafelM = new TMTafel(pnlResMain));
					 table.repaint();
					 table.revalidate();
					 
			    }
			    
				
				catch(Exception e)
				{
					
				
			 }
	}

}
}